﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Properties;
using ITAP.ShprossesBuilder.Modelling.Components;
using System.Drawing;
using ITAP.ShprossesBuilder.Modelling;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationZoomAutoForModel : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Авторазмер для модели"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.Other; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return Resources.AutoForModel.ToBitmap(); }
        }

        public void Execute(ModelControl modelControl)
        {
            ModelCell modelCell = modelControl.ModelContainer.ActiveCell as ModelCell;
            if (modelCell == null)
                return;

            RectangleF modelRectangle = modelCell.Model.BoundingBox;
            double scale = modelControl.CoordinateConverter.GetFullViewScale(modelControl.Width, modelControl.Height, modelRectangle);
            ModelPoint cameraCenter = new ModelPoint(modelRectangle.X + modelRectangle.Width / 2, modelRectangle.Y + modelRectangle.Height / 2);
            modelControl.CoordinateConverter.UseAutoScale = false;
            modelControl.CoordinateConverter.Scale = scale;
            modelControl.Camera = cameraCenter;
            modelRectangle = modelControl.Render.GetModelBoundingBoxAfterDrawing(modelCell, modelControl.Width, modelControl.Height);
            scale = modelControl.CoordinateConverter.GetFullViewScale(modelControl.Width, modelControl.Height, modelRectangle);
            modelControl.CoordinateConverter.UseAutoScale = false;
            modelControl.CoordinateConverter.Scale = scale;
            cameraCenter = new ModelPoint(modelRectangle.X + modelRectangle.Width / 2, modelRectangle.Y + modelRectangle.Height / 2);
            modelControl.Camera = cameraCenter;

        }

        public bool CanUndo
        {
            get { return false; }
        }

        #endregion
    }
}
